"""
Common base types for application components
"""
from pspy.der import PspyAction
__version__ = "0,0,1"

__all__ = ['PSWXAction']

class PSWXAction(PspyAction):
	"""
	Base class for all actions in module
	"""
	
	def _auth_check(self):
		"""
		Be sure we know who we are talking to...
		"""
		return True
	
	def errorExit(self, msg=None, page=None):
		"""
		Common exit strategy for error
		conditions.
		"""
		req = self._request
		
		errPage = "error/appError.kid"
		errMsg = "Application Error" 
		
		# check for customizations
		if msg:
			errMsg = "%s: %s" % (errMsg, msg)
		if page:
			errPage = page
			
		# check for AJAX response requirements
		if req.getParameter("isAjax", "0") == "1":
			req.setAttribute("", "")
			req.setAttribute('resultCode', 500)
			req.setAttribute('resultMessage', errMsg)
			errPage = "error/ajaxAppError.kid"
			
		# prep response
		req.setResponsePage(errPage)
		
		# done
		return req.getResponse()
	
